package com.wkh.cli;

import com.wkh.cli.command.ConfigCommand;
import com.wkh.cli.command.GeneratorCommand;
import com.wkh.cli.command.ListCommand;
import picocli.CommandLine;

/**
 * @author wkh
 * 主命令，命令执行器，负责绑定所有子命令，并且提供执行命令的方法
 */
@CommandLine.Command(name = "main", mixinStandardHelpOptions = true)
public class CommandExecutor implements Runnable{

    private final CommandLine commandLine;
    {
        //全局初始化，这段代码没必要每次都执行
        commandLine = new CommandLine(this)
                .addSubcommand(new ConfigCommand())
                .addSubcommand(new GeneratorCommand())
                .addSubcommand(new ListCommand());
    }
    @Override
    public void run() {
        /**
         * 给出友好提示
         */
        System.out.println("请输入具体命令或输入 --help 查看命令提示");
    }

    /**
     * 执行命令的方法
     * @param args
     * @return
     */
    public Integer doExecutor(String[] args){
        return commandLine.execute(args);
    }
}
